package com.magic.gre.mvp.presenter;

import com.google.gson.reflect.TypeToken;
import com.magic.gre.entity.ChooseUnitBean;
import com.magic.gre.entity.ResAddressBean;
import com.magic.gre.entity.base.BaseListModel;
import com.magic.gre.entity.base.BaseObjectModel;
import com.magic.gre.mvp.contract.ChooseUnitContract;
import com.magic.gre.mvp.model.ChooseUnitModelImpl;
import com.noname.lib_base_java.mvp.BasePresenterImpl;
import com.noname.lib_base_java.net.download.DownloadInfo;
import com.noname.lib_base_java.util.L;

/**
 * Author: Lmoumou
 * Date: 2019-01-08 10:11
 * 文件名: ChooseUnitPresenterImpl
 * 描述:
 */
public class ChooseUnitPresenterImpl extends BasePresenterImpl<ChooseUnitContract.View, ChooseUnitContract.Model>
        implements ChooseUnitContract.Presenter {
    public ChooseUnitPresenterImpl(ChooseUnitContract.View view) {
        super(view);
    }

    @Override
    protected ChooseUnitContract.Model creatModel() {
        return new ChooseUnitModelImpl();
    }

    @Override
    public void pUnitList(String thesaurusId) {
        mModel.mUnitList(new CommonObserver<BaseListModel<ChooseUnitBean>>(new TypeToken<BaseListModel<ChooseUnitBean>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseListModel<ChooseUnitBean> chooseUnitBeanBaseListModel) {
                mView.vUnitList(chooseUnitBeanBaseListModel.body);
            }

            @Override
            public void onError(int status, String msg) {

            }
        }, thesaurusId);
    }

    @Override
    public void pResourcesAddress(String id) {
        mModel.mResourcesAddress(new CommonObserver<BaseObjectModel<DownloadInfo>>(new TypeToken<BaseObjectModel<DownloadInfo>>(){}.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<DownloadInfo> stringBaseObjectModel) {
                mView.vResourcesAddress(stringBaseObjectModel.body);
            }

            @Override
            public void onError(int status, String msg) {
                mView.doPrompt(msg);
            }
        }, id);
    }

    @Override
    public void pLastUnit(final String unitId, final String name) {
        mModel.mLastUnit(new CommonObserver<BaseObjectModel<String>>(new TypeToken<BaseObjectModel<String>>() {
        }.getType()) {
            @Override
            protected void onSuccess(BaseObjectModel<String> baseObjectModel) {
                L.e("ChooseUnitPresenterImpl","onSuccess");
                mView.vLastUnit(baseObjectModel.body,unitId,name);
            }

            @Override
            public void onError(int status, String msg) {
                L.e("ChooseUnitPresenterImpl","onError->"+msg);
            }
        }, unitId);
    }
}
